package org.datastructure.firstday.hashtable;

public class HashTable {
    public int size;
    public EmpLinkedList[] empLinkedLists;

    public HashTable(int size) {
        this.size = size;
        empLinkedLists = new EmpLinkedList[size];
        for (int i = 0; i < size; i++) {
            empLinkedLists[i] = new EmpLinkedList();
        }
    }

    public int hashFun(int id) {
        return id % size;
    }

    public void add(Employees employees) {
        int empLinkedListNO = hashFun(employees.id);
        empLinkedLists[empLinkedListNO].addEmp(employees);
    }

    public void list() {
        for (int i = 0; i < size; i++) {
            empLinkedLists[i].list(i);
        }
    }

    public Employees getEmployee(int id) {
        int hash = hashFun(id);
        return empLinkedLists[hash].getEmployee(id);
    }
}
